home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 24 / CU Amiga Magazine's Super CD-ROM 24 (1998)(EMAP Images)(GB)(Track 1 of 2)[!][issue 1998-07].iso / CUCD / Utilities / vim-5.1 / doc / syntax.txt < prev    next >
Encoding:
Text File  |  1998-04-06  |  61.2 KB  |  1,530 lines

  1. *syntax.txt*    For Vim version 5.1.  Last modification: 1998 Apr 06
  2.  
  3.  
  4.           VIM REFERENCE MANUAL    by Bram Moolenaar
  5.  
  6.  
  7. Syntax highlighting        *syntax* *syntax-highlighting* *coloring*
  8.  
  9. Syntax highlighting enables the possibility to show parts of the text in
  10. another font or color.  Those parts can be specific keywords or text
  11. matching a pattern.  Vim doesn't parse the whole file (to keep it fast), so
  12. the highlighting has its limitations.  Lexical highlighting might be a
  13. better name, but everybody calls it syntax highlighting, so we'll stick with
  14. that.
  15.  
  16. Vim supports syntax highlighting on all terminals.  But since most ordinary
  17. terminals have very limited highlighting possibilities, it works best in the
  18. GUI version, gvim.
  19.  
  20. 1.  Quick start         |:syn-qstart|
  21. 2.  Syntax files     |:syn-files|
  22. 3.  Syntax file remarks     |:syn-file-remarks|
  23. 4.  Defining a syntax     |:syn-define|
  24. 5.  :syntax arguments     |:syn-arguments|
  25. 6.  Syntax patterns     |:syn-pattern|
  26. 7.  Synchronizing     |:syn-sync|
  27. 8.  Listing syntax items |:syntax|
  28. 9.  Highlight command     |:highlight|
  29. 10. Linking groups     |:highlight-link|
  30. 11. Cleaning up         |:syn-clear|
  31. 12. Highlighting tags     |tag-highlight|
  32. 13. Color xterms     |xterm-color|
  33.  
  34. {Vi does not have any of these commands}
  35.  
  36. The syntax highlighting is not available when the |+syntax| feature has been
  37. disabled at compile time.
  38.  
  39. ==============================================================================
  40. 1. Quick start                        *:syn-qstart*
  41.  
  42.                             *:syn-on*
  43. For a large number of common languages syntax files have been included.  To
  44. start using them, type this command:
  45. >  :syntax on
  46.  
  47. This will enable automatic syntax highlighting.  The type of highlighting will
  48. be selected using the file name extension, and sometimes using the first line
  49. of the file.
  50.  
  51. Include this command in your .vimrc if you always want syntax highlighting, or
  52. put it in your .gvimrc if you only want it in the GUI.  If you don't want it
  53. for B&W terminals, but you do want it for color terminals, put this in your
  54. .vimrc:
  55. >  if &t_Co > 1
  56. >    syntax on
  57. >  endif
  58.  
  59. What this command actually does, is executing the command
  60. >  source $VIM/syntax/syntax.vim
  61. If the VIM environment variable is not set, Vim will try to find
  62. the path in another way (see |$VIM|).  Normally this will work just fine.  If
  63. it doesn't, try setting the VIM environment variable to the directory where
  64. the Vim stuff is located.  For example, if your syntax files are in the
  65. "/usr/vim/5.0/syntax" directory, set $VIM to "/usr/vim/5.0".  You must do this
  66. in the shell, before starting Vim.
  67.  
  68.                             *:syn-default-override*
  69. You can override the default highlight settings, by issuing ":highlight"
  70. commands after sourcing "syntax.vim".  For example:
  71. >  syntax on
  72. >  highlight Constant gui=NONE guibg=grey95
  73.  
  74. This will change the GUI highlighting for the "Constant" group.  See
  75. |:highlight| about how to specify highlighting attributes.
  76.  
  77. If you are running in the GUI, you can get white text on a black background
  78. with:
  79. >  highlight Normal guibg=Black guifg=White
  80.  
  81. If you have a black background, use these commands to get better colors (see
  82. 'background'):
  83. >  set background=dark
  84. >  syntax on
  85.  
  86. NOTE: The syntax files on MS-DOS and Windows have lines that end in <CR><NL>.
  87. The files for Unix end in <NL>.  This means you should use the right type of
  88. file for your system.  Although on MS-DOS and Windows the right format is
  89. automatically selected if the 'fileformats' option is not empty.
  90.  
  91. NOTE: When using reverse video ("gvim -fg white -bg black"), the default value
  92. of 'background' will not be set until the GUI window is opened, which is after
  93. reading the .gvimrc.  This will cause the wrong default highlighting to be
  94. used.  To set the default value of 'background' before switching on
  95. highlighting, include the ":gui" command in the .gvimrc:
  96.  
  97. >  :gui        " open window and set default for 'background'
  98. >  :syntax on    " start highlighting, use 'background' to set colors
  99.  
  100.  
  101. To switch off the syntax highlighting:            *:syn-off*
  102. >  :syntax off
  103.  
  104. You can toggle the syntax on/off with this command
  105. >  :if has("syntax_items") | syntax off | else | syntax on | endif
  106.  
  107. To put this into a mapping, you can use:
  108. >  map <F7> :if has("syntax_items") <Bar> syntax off <Bar> else <Bar> syntax on <Bar> endif <CR>
  109. [using the |<>| notation, type this literally]
  110.  
  111. ==============================================================================
  112. 2. Syntax files                        *:syn-files*
  113.  
  114. The syntax and highlighting commands for one language are normally stored in
  115. a syntax file.  The name convention is: "{name}.vim".  Where {name} is the
  116. name of the language, or an abbreviation (to fit the name in 8.3 characters,
  117. which is always done, in case the file will be used on a DOS filesystem).
  118. Examples:
  119.     c.vim        perl.vim    java.vim    html.vim
  120.     cpp.vim        sh.vim        csh.vim
  121.  
  122. The syntax file can contain any Ex commands, just like a vimrc file.  But
  123. the idea is that only commands for a specific language are included.  When a
  124. language is a superset of another language, it may include the other one,
  125. for example, the cpp.vim file could include the c.vim file:
  126. >  :so $VIM/syntax/c.vim
  127.  
  128. The .vim files are normally loaded with an autocommand.  For example:
  129. >  :au BufNewFile,BufReadPost *.c,*.h source $VIM/syntax/c.vim
  130. >  :au BufNewFile,BufReadPost *.cpp source $VIM/syntax/cpp.vim
  131.  
  132.  
  133. MAKING YOUR OWN SYNTAX FILES                *mysyntaxfile*
  134.  
  135. When you create your own syntax files, and you want to have these
  136. automatically used with ":syntax on", do this:
  137.  
  138. 1. Create a file that contains the autocommands to load your syntax file when
  139.    the right file name or extension is detected.  To prevent loading two
  140.    syntax files (when the extension is used twice), first delete other
  141.    autocommands for the same extension.  You can also include ":highlight"
  142.    commands in this file, which override the normal highlighting (because the
  143.    file is sourced after setting the normal highlighting).  Example:
  144. >    augroup syntax
  145. >    au! BufNewFile,BufReadPost *.bat
  146. >    au  BufNewFile,BufReadPost *.bat  so ~/vim/batch.vim
  147. >    augroup END
  148. >    highlight Comment gui=bold
  149.    Let's assume you write this file in "~/vim/mysyntax.vim".
  150.  
  151. 2. In your .vimrc, set the "mysyntaxfile" variable to the file you just
  152.    created.  For example:
  153. >  :let mysyntaxfile = "~/vim/mysyntax.vim"
  154.  
  155. 3. If your file type can only be detected by inspecting the contents of the
  156.    file, create another file for doing this.  See $VIM/syntax/scripts.vim for
  157.    examples.  Let's assume you write this file in "~/vim/myscripts.vim".
  158.    Then set the "myscriptsfile" variable to this file name.  Example:
  159. >  :let myscriptsfile = "~/vim/myscripts.vim"
  160.    Note that this file is only used when no syntax file was loaded by the
  161.    autocommands, if the file type has not been detected by the file name or
  162.    extension.
  163.  
  164. Note that "mysyntaxfile" is sourced AFTER defining the default autocommands
  165. for the supplied syntax files, so you can override these with your own files.
  166. The "myscriptsfile" is loaded before the default checks for syntax files,
  167. which also means that your rules override the supplied rules.
  168.  
  169.  
  170. NAMING CONVENTIONS
  171.                             *group-name*
  172. To be able to allow each user to pick his favorite set of colors, there need
  173. to be preferred names for highlight groups that are common for many languages.
  174. These are the ones that are suggested to be used:
  175.  
  176.     *Comment    any comment
  177.  
  178.     *Constant    any constant
  179.      String        a string constant: "this is a string"
  180.      Character    a character constant: 'c', '\n'
  181.      Number        a number constant: 234, 0xff
  182.      Boolean    a boolean constant: TRUE, false
  183.      Float        a floating point constant: 2.3e10
  184.  
  185.     *Identifier    any variable name
  186.      Function    function name (also: methods for classes)
  187.  
  188.     *Statement    any statement
  189.      Conditional    if, then, else, endif, switch, etc.
  190.      Repeat        for, do, while, etc.
  191.      Label        case, default, etc.
  192.      Operator    "sizeof", "+", "*", etc.
  193.      Keyword    any other keyword
  194.      Exception    try, catch, throw
  195.  
  196.     *PreProc    generic Preprocessor
  197.      Include    preprocessor #include
  198.      Define        preprocessor #define
  199.      Macro        same as Define
  200.      PreCondit    preprocessor #if, #else, #endif, etc.
  201.  
  202.     *Type        int, long, char, etc.
  203.      StorageClass    static, register, volatile, etc.
  204.      Structure    struct, union, enum, etc.
  205.      Typedef    A typedef
  206.  
  207.     *Special    any special symbol
  208.      SpecialChar    special character in a constant
  209.      Tag        you can use CTRL-] on this
  210.      Delimiter    character that needs attention
  211.      SpecialComment    special things inside a comment
  212.      Debug        debugging statements
  213.  
  214.     *Error        any erroneous construct
  215.  
  216.     *Todo        anything that needs extra attention
  217.  
  218. The ones marked with * are the preferred groups, the other are minor groups.
  219. For the preferred groups, the "syntax.vim" file contains default highlighting.
  220. The minor groups are linked to the preferred groups, so they get the same
  221. highlighting.  You can override these defaults by giving ":highlight" commands
  222. after sourcing the "syntax.vim" file.
  223.  
  224. Note that highlight group names are not case sensitive.  "String" and "string"
  225. can be used for the same group.
  226.  
  227. The following names are reserved and cannot be used as a group name:
  228.     NONE   ALL   ALLBUT   contains   contained
  229.  
  230. ==============================================================================
  231. 3. Syntax file remarks                    *:syn-file-remarks*
  232.  
  233.                         *current_syntax-variable*
  234. The name of the syntax that has been loaded is stored in the "current_syntax"
  235. variable.  You can use this if you want to load other settings, depending on
  236. which syntax is active.  Example:
  237. >  :au BufReadPost * if current_syntax == "csh"
  238. >  :au BufReadPost *   do-some-things
  239. >  :au BufReadPost * endif
  240.  
  241.  
  242. 2HTML                        *2html.vim* *convert-to-HTML*
  243.  
  244. This is not a syntax file itself, but a script that converts the current
  245. window into HTML.  A new window is opened, in which the HTML file is built.
  246.     Warning: This is slow!
  247. The resulting file can be written where you want it.  You can then view it
  248. with any HTML viewer, such as Netscape.  The colors should be exactly the same
  249. as you see them in Vim.  From Netscape you can also print the file (in color)!
  250. This only works in the GUI version.  When 'tabstop' is not 8, the amount of
  251. white space will be wrong.
  252.  
  253.  
  254. C                            *c.vim*
  255.  
  256. Most C highlighting is fixed.  There is one optional feature: highlighting
  257. strings and numbers inside a comment.  It can be enabled by adding this line
  258. to your vimrc:
  259. >  let c_comment_strings=1
  260. To disable it again, use this:
  261. >  unlet c_comment_strings
  262.  
  263. If you notice highlighting errors while scrolling backwards, which are fixed
  264. when redrawing with CTRL-L, try setting the "c_minlines" internal variable
  265. to a larger number:
  266. >  let c_minlines = 50
  267. This will make the syntax synchronisation start 50 lines before the first
  268. displayed line.  The default value is 10.  The disadvantage of using a larger
  269. number is that redrawing can become slow.
  270.  
  271.  
  272. COBOL                            *cobol.vim*
  273.  
  274. COBOL highlighting for legacy code has different needs than fresh development.
  275. This is due both to differences in what is being done (maintenance versus
  276. development) as well as other factors.  To enable legacy code highlighting,
  277. add this line to you .vimrc:
  278. >  let cobol_legacy_code=1
  279. To disable it again, use this:
  280. >  unlet cobol_legacy_code
  281.  
  282.  
  283. EIFFEL                            *eiffel.vim*
  284.  
  285. While Eiffel is not case-sensitive, its style guidelines are, and the
  286. syntax highlighting file encourages their use. This also allows to
  287. highlight class names differently. If you want to disable case-sensitive
  288. highlighting, add the following line to your startup file:
  289.  
  290. >  let eiffel_ignore_case=1
  291.  
  292. Case still matters for class names and TODO marks in comments.
  293.  
  294. Conversely, for even stricter checks, add the following line too:
  295.  
  296. >  let eiffel_pedantic=1
  297.  
  298. Currently, this will only catch improper capitalization for the five
  299. predefined words "Current", "Void", "Result", "Precursor", and "NONE",
  300. to warn against their accidental use as feature or class names.
  301.  
  302. If instead you want to use the lower-case version of "Current", "Void",
  303. "Result", and "Precursor", you can use
  304.  
  305. >  let eiffel_lower_case_predef=1
  306.  
  307. instead of completely turning case-sensitive highlighting off.
  308.  
  309. Finally, some vendors support hexadecimal constants. To handle them, add
  310.  
  311. >  let eiffel_hex_constants=1
  312.  
  313. to your startup file.
  314.  
  315.  
  316. HTML                            *html.vim*
  317.  
  318. The coloring scheme for tags in the HTML file works as follows.
  319.  
  320. The  <> of opening tags are colored differently than the </> of a closing tag.
  321. This is on purpose! For opening tags the 'Function' color is used, while for
  322. closing tags the 'Type' color is used (See syntax.vim to check how those are
  323. defined for you)
  324.  
  325. Known tag names are colored the same way as statements in C.  Unknown tag
  326. names are colored with the same color as the <> or </> respectively which
  327. makes it easy to spot errors
  328.  
  329. Note that the same is true for argument (or attribute) names. Known attribute
  330. names are colored differently than unknown ones.
  331.  
  332. Some HTML tags are used to change the rendering of text. The following tags
  333. are recognized by the html.vim syntax coloring file and change the way normal
  334. text is shown: <B> <I> <U> <EM> <STRONG> (<EM> is used as an alias for <I>,
  335. while <STRONG> as an alias for <B>), <H1> - <H6>, <HEAD>, <TITLE> and <A>, but
  336. only if used as a link that is, it must include a href as in
  337. <A href="somfile.html">).
  338.  
  339. If you want to change how such text is rendered, you must redefine the
  340. following syntax groups:
  341.  
  342.     - htmlBold
  343.     - htmlBoldUnderline
  344.     - htmlBoldUnderlineItalic
  345.     - htmlUnderline
  346.     - htmlUnderlineItalic
  347.     - htmlItalic
  348.     - htmlLink for links
  349.     - htmlTitle for titles
  350.     - htmlH1 - htmlH6 for headings
  351.  
  352. To make this redefinition work you must redefine them all with the exception
  353. of the last two (htmlTitle and htmlH[1-6], which are optional) and define the
  354. following variable in your vimrc (this is due to the order in which the files
  355. are read during initialization)
  356. >   let html_my_rendering=1
  357.  
  358. If you'd like to see an example download mysyntax.vim at
  359. http://www.fleiner.com/vim/mysyntax.vim
  360.  
  361. You can also disable this rendering by adding the following line to your
  362. vimrc file:
  363. >   let html_no_rendering=1
  364.  
  365. HTML comments are rather special (see an HTML reference document for the
  366. details), and the syntax coloring scheme will highlight all errors.
  367.  
  368. JavaScript embedded inside HTML documents is highlighted as 'Special'
  369. with statements, comments, strings and so on colored as in standard
  370. programming languages. Note that only JavaScript is currently supported,
  371. no other scripting language has been added yet.
  372.  
  373.  
  374. JAVA                            *java.vim*
  375.  
  376. The java.vim syntax highlighting file offers several options:
  377.  
  378. In Java 1.0.2 it was never possible to have braces inside parens, so this was
  379. flagged as an error.  Since Java 1.1 this is possible (with anonymous
  380. classes), and therefore is no longer marked as an error. If you prefer the old
  381. way, put the following line into your vim startup file:
  382. >  let java_mark_braces_in_parens_as_errors=1
  383.  
  384. Function names are not highlighted, as the way to find functions depends on
  385. how you write java code.  To enable it anyway put the following line in your
  386. startup file:
  387. >  let java_highlight_functions=1
  388. This will only work if you either use two spaces for indentation or tabs.  If
  389. you use another indentation style but would still want function declarations
  390. to be highlighted create your own definitions by changing the definitions in
  391. java.vim or by creating your own java.vim which includes the original one and
  392. then adds the code to highlight functions.
  393.  
  394. In java 1.1 the functions System.out.println() and System.err.println() should
  395. only be used for debugging. Therefor it is possible to highlight debugging
  396. statements differently. To do this you must add the following definition in
  397. your startup file:
  398. >  let java_highlight_debug=1
  399. The result will be that those statements are highlighted as 'Special'
  400. characters. If you prefer to have them highlighted differently you must define
  401. new highlightings for the following groups.:
  402.     Debug, DebugSpecial, DebugString, DebugBoolean, DebugType
  403. which are used for the statement itself, special characters used in debug
  404. strings, strings, boolean constants and types (this, super) respectively. I
  405. have opted to chose another background for those statements.
  406.  
  407. Javadoc is a program that takes special comments out of java program files and
  408. creates HTML pages. The standard configuration will highlight this HTML code
  409. similarly to HTML files (see |html.vim|). There are four differences:
  410.   1. The title (all characters up to the first '.' which is followed by
  411.      some white space or to the first '@') is colored differently (to change
  412.      the color change the group CommentTitle).
  413.   2. The text is colored as 'Comment'.
  414.   3. HTML comments are colored as 'Special'
  415.   4. Embedded JavaScript and the recognition of special tags like <B>
  416.      is currently not supported in order to keep the java.vim file reasonably
  417.      small.
  418. To turn this feature off add the following line to your startup file:
  419. >  let java_ignore_javadoc=1
  420.  
  421. If you notice highlighting errors while scrolling backwards, which are fixed
  422. when redrawing with CTRL-L, try setting the "java_minlines" internal variable
  423. to a larger number:
  424. >  let java_minlines = 50
  425. This will make the syntax synchronisation start 50 lines before the first
  426. displayed line.  The default value is 10.  The disadvantage of using a larger
  427. number is that redrawing can become slow.
  428.  
  429.  
  430. LACE                            *lace.vim*
  431.  
  432. Lace (Language for Assembly of Classes in Eiffel) is case insensitive, but the
  433. style guide lines are not.  If you prefer case insensitive highlighting, just
  434. define the vim variable 'lace_case_insensitive' in your startup file:
  435. >  let lace_case_insensitive=1
  436.  
  437.  
  438. REXX                            *rexx.vim*
  439.  
  440. If you notice highlighting errors while scrolling backwards, which are fixed
  441. when redrawing with CTRL-L, try setting the "rexx_minlines" internal variable
  442. to a larger number:
  443. >  let rexx_minlines = 50
  444. This will make the syntax synchronisation start 50 lines before the first
  445. displayed line.  The default value is 10.  The disadvantage of using a larger
  446. number is that redrawing can become slow.
  447.  
  448.  
  449. SH                            *sh.vim*
  450.  
  451. This covers the "normal" Unix sh, bash and the korn shell.  If you're working
  452. on a system where bash is called sh, you will benefit to define the vim
  453. variable 'bash_is_sh' in your '.vimrc' file:
  454. >  let bash_is_sh = 1
  455.  
  456. To choose between the two ways to treat single-quotes inside a pair of
  457. double-quotes, I have introduced a Vim variable "highlight_balanced_quotes".
  458. By default (ie by not declaring this variable) single quotes can be used
  459. inside double quotes, and are not highlighted.  If you prefer balanced single
  460. quotes as I do you just make the statement in your .vimrc file:
  461. >  let highlight_balanced_quotes = 1
  462.  
  463. Similar I have introduced another vim variable "highlight_function_name" to be
  464. used to enable/disable highlighting of the function-name in function
  465. declaration.  Default is not to highlight the function name.  If you want to
  466. highlight functions names, include this in your .vimrc file:
  467. >  let highlight_function_name = 1
  468.  
  469. If you notice highlighting errors while scrolling backwards, which are fixed
  470. when redrawing with CTRL-L, try setting the "sh_minlines" internal variable
  471. to a larger number:
  472. >  let sh_minlines = 200
  473. This will make the syntax synchronisation start 200 lines before the first
  474. displayed line.  The default value is 100.  The disadvantage of using a larger
  475. number is that redrawing can become slow.
  476.  
  477. ==============================================================================
  478. 4. Defining a syntax                    *:syn-define*
  479.  
  480. Vim understands three types of syntax items:
  481. 1. A keyword.  It can only contain keyword characters, according to the
  482.    'iskeyword' option.  It cannot contain other syntax items.  It will only
  483.    be recognized when it is a complete match (there are no keyword
  484.    characters before or after the match).  "if" would match in "if(a=b)",
  485.    but not in "ifdef x".
  486. 2. A match.  This is a match with a single regexp pattern.  It must be within
  487.    one line.
  488. 3. A region.  This starts at a match of the start regexp pattern and
  489.    ends with a match with the end regexp pattern.  A skip regexp pattern can
  490.    be used to avoid matching the end pattern.
  491.  
  492. Several syntax ITEMs can be put into one syntax GROUP.  For a syntax group
  493. you can give highlighting attributes.  For example, you could have an item
  494. to define a "/* .. */" comment and another one that defines a "// .." comment,
  495. and put them both in the "Comment" group.  You can then specify that a
  496. "Comment" will be in bold font and have a blue color.  You are free to make
  497. one highlight group for one syntax item, or put all items into one group.
  498. This depends on how you want to specify your highlighting attributes.  Putting
  499. each item in its own group results in having to specify the highlighting
  500. for a lot of groups.
  501.  
  502. Note that a syntax group and a highlight group are similar.  For a highlight
  503. group you will have given highlight attributes.  These attributes will be used
  504. for the syntax group with the same name.
  505.  
  506. In case more than one item matches at the same position, the one that was
  507. defined LAST wins.  Thus you can override previously defined syntax items by
  508. using an item that matches the same text.  But a keyword always goes before a
  509. match or region.  And a keyword with matching case always goes before a
  510. keyword with ignoring case.
  511.  
  512.  
  513. DEFINING CASE                        *:syn-case*
  514.  
  515. :syntax case [match|ignore]
  516.     This defines if the following ":syntax" commands will work with
  517.     matching case, when using "match", or with ignoring case, when using
  518.     "ignore".  Note that any items before this are not affected, and all
  519.     items until the next ":syntax case" command are affected.
  520.  
  521.  
  522. DEFINING KEYWORDS                    *:syn-keyword*
  523.  
  524. :syntax keyword {group-name} [{options}] {keyword} .. [{options}]
  525.  
  526.     This defines a number of keywords.
  527.  
  528.     {group-name}    Is a syntax group name such as "Comment".
  529.     [{options}]    See |:syn-arguments| below.
  530.     {keyword} ..    Is a list of keywords which are part of this group.
  531.  
  532.     Example:
  533. >  :syntax keyword   Type   int long char
  534.  
  535.     The {options} can be given anywhere in the line.  They will apply to
  536.     all keywords given, also for options that come after a keyword.
  537.     These examples do exactly the same:
  538. >  :syntax keyword   Type   contained int long char
  539. >  :syntax keyword   Type   int long contained char
  540. >  :syntax keyword   Type   int long char contained
  541.  
  542.     When you have a keyword with an optional tail, like Ex commands in
  543.     Vim, you can put the optional characters inside [], to define all the
  544.     variations at once:
  545. >  :syntax keyword   VimCommand   ab[breviate] n[ext]
  546.  
  547.     A keyword always has higher priority than a match or region, the
  548.     keyword is used if more than one item matches.  Keywords do not nest
  549.     and a keyword can't contain anything else.
  550.  
  551.     Note that when you have a keyword that is the same as an option (even
  552.     one that isn't allowed here), you can not use it.  Use a match
  553.     instead.
  554.  
  555.     The maximum length of a keyword is 80 characters.
  556.  
  557.     The same keyword can be defined multiple times, when its containment
  558.     differs.  For example, you can define the keyword once not contained
  559.     and use one highlight group, and once contained, and use a different
  560.     highlight group. Example:
  561. >  :syn keyword vimCommand tag
  562. >  :syn keyword vimSetting contained tag
  563.     When finding "tag" outside of any syntax item, the "vimCommand"
  564.     highlight group is used.  When finding "tag" in a syntax item that
  565.     contains "vimSetting", the "vimSetting" group is used.
  566.  
  567.  
  568. DEFINING MATCHES                    *:syn-match*
  569.  
  570. :syntax match {group-name} [{options}] {pattern} [{options}]
  571.  
  572.     This defines one match.
  573.  
  574.     {group-name}        A syntax group name such as "Comment".
  575.     [{options}]        See |:syn-arguments| below.
  576.     {pattern}        The search pattern that defines the match.
  577.                 See |:syn-pattern| below.
  578.  
  579.     Example (match a character constant):
  580. >  :syntax match Character /'.'/s+1e-1
  581.  
  582.  
  583. DEFINING REGIONS    *:syn-region* *:syn-start* *:syn-skip* *:syn-end*
  584.  
  585. :syntax region {group-name} [{options}]
  586.         [matchgroup={group_name}]
  587.         [keepend]
  588.         start={start_pattern} ..
  589.         [skip={skip_pattern}]
  590.         end={end_pattern} ..
  591.         [{options}]
  592.  
  593.     This defines one region.  It may span several lines.
  594.  
  595.     {group-name}        A syntax group name such as "Comment".
  596.     [{options}]        See |:syn-arguments| below.
  597.     [matchgroup={group-name}]  The syntax group to use for the following
  598.                 start or end pattern matches only.  Not used
  599.                 for the text in between the matched start and
  600.                 end patterns.  Use NONE to reset to not using
  601.                 a different group for the start or end match.
  602.                 See |:syn-matchgroup|.
  603.     keepend            Don't allow contained matches to go past a
  604.                 match with the end pattern.  See
  605.                 |:syn-keepend|.
  606.     start={start_pattern}    The search pattern that defines the start of
  607.                 the region.  See |:syn-pattern| below.
  608.     skip={skip_pattern}    The search pattern that defines text inside
  609.                 the region where not to look for the end
  610.                 pattern.  See |:syn-pattern| below.
  611.     end={end_pattern}    The search pattern that defines the end of
  612.                 the region.  See |:syn-pattern| below.
  613.  
  614.     Example:
  615. >  :syntax region String   start=+"+  skip=+\\"+  end=+"+
  616.  
  617.     The start/skip/end patterns and the options can be given in any order.
  618.     There can be zero or one skip pattern.  There must be one or more
  619.     start and end patterns.  This means that you can omit the skip
  620.     pattern, but you must give at least one start and one end pattern.  It
  621.     is allowed to have white space before and after the equal sign
  622.     (although it mostly looks better without white space).
  623.  
  624.     When more than one start pattern is given, a match with one of these
  625.     is sufficient.  This means there is an OR relation between the start
  626.     patterns.  The first one that matches is used.  The same is true for
  627.     the end patterns.
  628.  
  629.     The search for the end pattern starts at the start of the region.
  630.     This implies that it can also match inside the start pattern!
  631.  
  632.     Note: The decision to start a region is only based on a matching start
  633.     pattern.  There is no check for a matching end pattern.  This does NOT
  634.     work:
  635.         :syn region First  start="("  end="."
  636.         :syn region Second start="("  end=";"
  637.     The Second always matches before the First (last defined pattern has
  638.     higher priority).  The Second region then continues until the next
  639.     ';', no matter if there is a '.' before it.
  640.  
  641.                             *:syn-keepend*
  642.     By default, a contained match can obscure a match for the end pattern.
  643.     This is useful for nesting.  For example, a region that starts with
  644.     "{" and ends with "}", can contain another region.  An encountered "}"
  645.     will then end the contained region, but not the outer region:
  646.         {        starts outer "{}" region
  647.         {    starts contained "{}" region
  648.         }    ends contained "{}" region
  649.         }        ends outer "{} region
  650.     If you don't want this, the "keepend" argument will make the matching
  651.     of an end pattern of the outer region also end any contained item.
  652.     This makes it impossible to nest the same region, but allows for
  653.     contained items to highlight parts of the end pattern, without causing
  654.     that to skip the match with the end pattern.  Example:
  655. >  :syn match  VimComment +"[^"]\+$+
  656. >  :syn region VimCommand start="set" end="$" contains VimComment keepend
  657.     The "keepend" makes the VimCommand always end at the end of the line,
  658.     even though the contained VimComment includes a match with the <EOL>.
  659.  
  660.     When "keepend" is not used, a match with an end pattern is retried
  661.     after each contained match.  When "keepend" is included, the first
  662.     encountered match with an end pattern is used, truncating any
  663.     contained matches.
  664.  
  665.                             *:syn-matchgroup*
  666.     "matchgroup" can be used to highlight the start and/or end pattern
  667.     differently than the body of the region.  Example:
  668. >  :syntax region String matchgroup=Quote start=+"+  skip=+\\"+  end=+"+
  669.     This will highlight the quotes with the "Quote" group, and the text in
  670.     between with the "String" group.
  671.     The "matchgroup" is used for all start and end patterns that follow,
  672.     until the next "matchgroup".  Use "matchgroup=NONE" to go back to not
  673.     using a matchgroup.
  674.  
  675.     It is not possible to have a contained match in a start or end pattern
  676.     that is highlighted with "matchgroup".
  677.     When using "transparent", it does not apply to a start or end pattern
  678.     that is highlighted with "matchgroup".
  679.  
  680. ==============================================================================
  681. 5. :syntax arguments                    *:syn-arguments*
  682.  
  683. The :syntax commands that define syntax items take a number of arguments.
  684. The common ones are explained here.  The arguments may be given in any order
  685. and may be mixed with patterns.
  686.  
  687. Not all commands accept all arguments.  This table shows which arguments
  688. can be used for each command:
  689.  
  690.          contained  nextgroup  skip*   transparent  contains  oneline ~
  691. :syntax keyword        yes           yes    yes       yes       -     -
  692. :syntax match        yes           yes    yes       yes          yes     -
  693. :syntax region        yes           yes    yes       yes          yes    yes
  694.  
  695.  
  696. contained                        *:syn-contained*
  697.  
  698. When the "contained" argument is given, this item will not be recognized at
  699. the top level, but only when it is mentioned in the "contains" field of
  700. another match.  Example:
  701. >   :syntax keyword Todo    TODO    contained
  702. >   :syntax match   Comment "//.*"  contains=Todo
  703.  
  704.  
  705. transparent                        *:syn-transparent*
  706.  
  707. If the "transparent" argument is given, this item will not be highlighted
  708. itself, but will take the highlighting of the item it is contained in.  This
  709. is useful for syntax items that don't need any highlighting but are used
  710. only to skip over a part of the text.  The same groups as the item it is
  711. contained in are used, unless a "contains" argument is given too.
  712.  
  713.  
  714. oneline                            *:syn-oneline*
  715.  
  716. The "oneline" argument indicates that the region does not cross a line
  717. boundary.  It must match completely in the current line.  However, when the
  718. region has a contained item that does cross a line boundary, it continues on
  719. the next line anyway.  A contained item can be used to recognize a line
  720. continuation pattern.
  721.  
  722.  
  723. contains={groupname},..                    *:syn-contains*
  724.  
  725. The "contains" argument is followed by a list of syntax group names.  These
  726. groups will be allowed to begin inside the item (they may extend past the
  727. containing group's end).  This allows for recursive nesting of matches and
  728. regions.  If there is no "contains" argument, no groups will be contained in
  729. this item.  The group names do not need to be defined before they can be used
  730. here.
  731.  
  732. contains=ALL
  733.         If the only item in the contains list is "ALL", then all
  734.         groups will be accepted inside the item.
  735.  
  736. contains=ALLBUT,{group-name},..
  737.         If the first item in the contains list is "ALLBUT", then all
  738.         groups will be accepted inside the item, except the ones that
  739.         are listed, and the "contained" items.  Example:
  740. >  :syntax region Block start="{" end="}" ... contains=ALLBUT,Function
  741.  
  742. The {group-name} in the "contains" list can be a pattern.  All group names
  743. that match the pattern will be included (or excluded, if "ALLBUT" is used).
  744. The pattern cannot contain white space or a ','.  Example:
  745. >  ... contains=Comment.*,Keyw[0-3]
  746.  
  747.  
  748. nextgroup={groupname},..                *:syn-nextgroup*
  749.  
  750. The "nextgroup" argument is followed by a list of syntax group names,
  751. separated by commas (just like with "contains", so you can also use patterns).
  752.  
  753. If the "nextgroup" argument is given, the mentioned syntax groups will be
  754. tried for a match, after the match or region ends.  If none of the groups have
  755. a match, highlighting continues normally.  If there is a match, this group
  756. will used, even when it is not mentioned in the "contains" field of the
  757. current group.  This is like giving the mentioned group priority over all
  758. other groups.  Example:
  759. >   :syntax match  ccFoobar  "Foo.\{-}Bar"  contains=ccFoo
  760. >   :syntax match  ccFoo     "Foo"        contained nextgroup=ccFiller
  761. >   :syntax region ccFiller  start="."  matchgroup=ccBar  end="Bar"  contained
  762.  
  763. This will highlight "Foo" and "Bar" differently, and only when there is a
  764. "Bar" after "Foo".  In the text line below, "f" shows where ccFoo is used for
  765. highlighting, and "bbb" where ccBar is used.
  766.  
  767. >   Foo asdfasd Bar asdf Foo asdf Bar asdf
  768. >   fff        bbb      fff      bbb
  769.  
  770. Note the use of ".\{-}" to skip as little as possible until the next Bar.
  771. when ".*" would be used, the "asdf" in between "Bar" and "Foo" would be
  772. highlighted according to the "ccFoobar" group, because the ccFooBar match
  773. would include the first "Foo" and the last "Bar" in the line (see |pattern|).
  774.  
  775.  
  776. skipwhite                        *:syn-skipwhite*
  777. skipnl                            *:syn-skipnl*
  778. skipempty                        *:syn-skipempty*
  779.  
  780. These arguments are only used in combination with "nextgroup".  They can be
  781. used to allow the next group to match after skipping some text:
  782.     skipwhite    skip over space and Tab characters
  783.     skipnl        skip over the end of a line
  784.     skipempty    skip over empty lines (implies a "skipnl")
  785.  
  786. When "skipwhite" is present, the white space is only skipped if there is no
  787. next group that matches the white space.
  788.  
  789. When "skipnl" is present, the match with nextgroup may be found in the next
  790. line.  This only happens when the current item ends at the end of the current
  791. line!  When "skipnl" is not present, the nextgroup will only be found after
  792. the current item in the same line.
  793.  
  794. When skipping text while looking for a next group, the matches for other
  795. groups are ignored.  Only when no next group matches, other items are tried
  796. for a match again.  This means that matching a next group and skipping white
  797. space and <EOL>s has a higher priority than other items.
  798.  
  799. Example:
  800. >  syn match ifstart "if.*"     nextgroup=ifline skipwhite skipempty
  801. >  syn match ifline  "endif"    contained
  802. >  syn match ifline  "[^ \t].*" nextgroup=ifline skipwhite skipempty contained
  803. Note that the last match, which matches any non-white text, is put last,
  804. otherwise the "endif" of the indent would never match, because the "[^ \t].*"
  805. would match first.
  806. Note that this example doesn't work for nested "if"s.  You need to add
  807. "contains" arguments to make that work (omitted for simplicity of the
  808. example).
  809.  
  810. ==============================================================================
  811. 6. Syntax patterns                    *:syn-pattern*
  812.  
  813. In the syntax commands, a pattern must be surrounded by two identical
  814. characters.  This is like it works for the ":s" command.  The most common to
  815. use is the double quote.  But if the pattern contains a double quote, you can
  816. use another character that is not used in the pattern.  Examples:
  817. >  :syntax region Comment  start="/\*"  end="\*/"
  818. >  :syntax region String   start=+"+    end=+"+   skip=+\\"+
  819.  
  820. See |pattern| for the explanation of what a pattern is.  Syntax patterns are
  821. always interpreted like the 'magic' options is set, no matter what the actual
  822. value of 'magic' is.  And the patterns are interpreted like the 'l' flag is
  823. not included in 'cpoptions'.  This was done to make syntax files portable and
  824. independent of 'compatible' and 'magic' settings.
  825.  
  826. Try to avoid patterns that can match an empty string, such as "[a-z]*".
  827. This slows down the highlighting a lot, because it matches everywhere.
  828.  
  829. The pattern can be followed by a character offset.  This can be used to
  830. change the highlighted part, and to change the text area included in the
  831. match or region (which only matters when trying to match other items).  Both
  832. are relative to the matched pattern.  The character offset for a skip
  833. pattern can be used to tell where to continue looking for an end pattern.
  834.  
  835. The offset takes the form of "{what}={offset}"
  836. The {what} can be one of six strings:
  837.  
  838. ms    Match Start    offset for the start of the matched text
  839. me    Match End    offset for the end of the matched text
  840. hs    Highlight Start    offset for where the highlighting starts
  841. he    Highlight End    offset for where the highlighting ends
  842. rs    Region Start    offset for where the body of a region starts
  843. re    Region End    offset for where the body of a region ends
  844. lc    Leading Context    offset past "leading context" of pattern
  845.  
  846. The {offset} can be:
  847.  
  848. s    start of the matched pattern
  849. s+{nr}    start of the matched pattern plus {nr} chars to the right
  850. s-{nr}    start of the matched pattern plus {nr} chars to the left
  851. e    end of the matched pattern
  852. e+{nr}    end of the matched pattern plus {nr} chars to the right
  853. e-{nr}    end of the matched pattern plus {nr} chars to the left
  854. {nr}    (for "lc" only): start matching {nr} chars to the left
  855.  
  856. Examples: "ms=s+1", "hs=e-2", "lc=3".
  857.  
  858. Although all offsets are accepted after any pattern, they are not always
  859. meaningful.  This table shows which offsets are actually used:
  860.  
  861.             ms   me   hs   he   rs   re      lc ~
  862. match item        yes  yes  yes  yes  -    -    yes
  863. region item start   yes  -    yes  -    yes  -    yes
  864. region item skip    -    yes  -    -    -    -    -
  865. region item end     -    yes  -    yes  -    yes  -
  866.  
  867. Offsets can be concatenated, with a ',' in between.  Example:
  868. >  syn match String  /".*"/hs=s+1,he=e-1
  869.  
  870.     some "string" text
  871.       ^^^^^^        highlighted
  872.  
  873. Notes:
  874. - There must be no white space between the pattern and the character
  875.   offset(s).
  876. - The highlighted area will never be outside of the matched text.
  877. - A negative offset for an end pattern may not always work, because the end
  878.   pattern may be detected when the highlighting should already have stopped.
  879.  
  880. Example (match a comment but don't highlight the /* and */):
  881. >  :syntax region Comment start="/\*"hs=e+1 end="\*/"he=s-1
  882.  
  883.     /* this is a comment */
  884.       ^^^^^^^^^^^^^^^^^^^     highlighted
  885.  
  886. A more complicated Example:
  887. >  :syn region Exa matchgroup=Foo start="foo"hs=s+2,rs=e+2 matchgroup=Bar end="bar"me=e-1,he=e-1,re=s-1
  888.  
  889.      abcfoostringbarabc
  890.         mmmmmmmmmmm        match
  891.           ssrrrreee        highlight start/region/end ("Foo", "Exa" and "Bar")
  892.  
  893. Leading context            *:syn-lc* *:syn-leading* *:syn-context*
  894.  
  895. The "lc" offset specifies leading context -- a part of the pattern that must
  896. be present, but is not considered part of the match.  An offset of "lc=n" will
  897. cause Vim to step back n columns before attempting the pattern match, allowing
  898. characters which have already been matched in previous patterns to also be
  899. used as leading context for this match.  This can be used, for instance, to
  900. specify that an "escaping" character must not precede the match:
  901.  
  902. >  :syn match ZNoBackslash "[^\\]z"ms=s+1
  903. >  :syn match WNoBackslash "[^\\]w"lc=1
  904. >  :syn match Underline "_\+"
  905.  
  906.       ___zzzz ___wwww
  907.       ^^^     ^^^      matches Underline
  908.           ^ ^      matches ZNoBackslash
  909.              ^^^^ matches WNoBackslash
  910.  
  911. The "ms" offset is automatically set to the same value as the "lc" offset,
  912. unless you set "ms" explicitly.
  913.  
  914. ==============================================================================
  915. 7. Synchronizing                    *:syn-sync*
  916.  
  917. Vim wants to be able to start redrawing in any position in the document.  To
  918. make this possible it needs to know the syntax item at the position where
  919. redrawing starts.
  920.  
  921. :syntax sync [ccomment [group-name] | minlines={N} | ...]
  922.  
  923. There are three ways to synchronize:
  924. 1. Based on C-style comments.  Vim understands how C-comments work and can
  925.    figure out if the current line starts inside or outside a comment.
  926. 2. Jumping back a certain number of lines and start parsing there.
  927. 3. Searching backwards in the text for a pattern to sync on.
  928.  
  929. For all three methods, the line range where the parsing can start is limited
  930. by "minlines" and "maxlines".
  931.  
  932. If the "minlines={N}" argument is given, the parsing always starts at least
  933. that many lines backwards.  This can be used if the parsing may take a few
  934. lines before it's correct, or when it's not possible to use syncing.
  935.  
  936. If the "maxlines={N}" argument is given, the number of lines that are searched
  937. for a comment or syncing pattern is restricted to N lines backwards (after
  938. adding "minlines".  This is useful if you have few things to sync on and a
  939. slow machine.  Example:
  940. >  :syntax sync ccomment maxlines=500
  941.  
  942.  
  943. First syncing method:
  944.  
  945. For the first method, only the "ccomment" argument needs to be given.
  946. Example:
  947. >  :syntax sync ccomment
  948.  
  949. When Vim finds that the line where displaying starts is inside a C-style
  950. comment, the first region syntax item with the group-name "Comment" will be
  951. used.  This requires that there is a region with the group-name "Comment"!
  952. An alternate group name can be specified, for example:
  953. >  :syntax sync ccomment javaComment
  954.  
  955. The "maxlines" argument can be used to restrict the search to a number of
  956. lines.  The "minlines" argument can be used to at least start a number of
  957. lines back (e.g., for when there is some construct that only takes a few
  958. lines, but it hard to sync on).
  959.  
  960. Note: Syncing on a C comment doesn't work properly when strings are used
  961. that cross al line and contain a "*/".  Since letting strings cross a line
  962. is a bad programming habit (many compilers give a warning message), and the
  963. chance of a "*/" appearing inside a comment is very small, this restriction
  964. is hardly ever noticed.
  965.  
  966.  
  967. Second syncing method:
  968.  
  969. For the second method, only the "lines={N}" argument needs to be given.  Vim
  970. will subtract {N} from the line number and start parsing there.  This means
  971. {N} extra lines need to be parsed, which makes this method a bit slower.
  972. Example:
  973. >  :syntax sync lines=50
  974.  
  975. "lines" and "minlines" are equivalent.
  976.  
  977.  
  978. Third syncing method:
  979.  
  980. The idea is to synchronize on the end of a few specific regions, called a
  981. sync pattern.  Only regions can cross lines, so when we find the end of some
  982. region, we might be able to know in which syntax item we are.  The search
  983. starts in the line just above the one where redrawing starts.  From there
  984. the search continues backwards in the file.
  985.  
  986. This works just like the non-syncing syntax ltems.  You can use contained
  987. matches, nextgroup, etc.  But there are a few differences:
  988. - Keywords cannot be used.
  989. - The syntax items with the "sync" keyword form a completely separated group
  990.   of syntax items.  You can't mix syncing groups and non-syncing groups.
  991. - The matching works backwards in the buffer (line by line), instead of
  992.   forwards.
  993. - A line continuation pattern can be given.  It is used to decide which group
  994.   of lines need to be searched like they were one line.  This means that the
  995.   search for a match with the specified items starts in the first of the
  996.   consecutive that contain the continuation pattern.
  997. - When using "nextgroup" or "contains", this only works within one line (or
  998.   group of continuated lines).
  999. - When a match with a sync pattern is found, the rest of the line (or group of
  1000.   continuated lines) is searched for another match.  The last match is used.
  1001.   This is used when a line can contain both the start end the end of a region
  1002.   (e.g., in a C-comment like /* this */, the last "*/" is used).
  1003.  
  1004. There are two ways how a match with a sync pattern can be used:
  1005. 1. Parsing for highlighting starts where redrawing starts (and where the
  1006.    search for the sync pattern started).  The syntax group that is expected
  1007.    to be valid there must be specified.  This works well when the regions
  1008.    that cross lines cannot contain other regions.
  1009. 2. Parsing for highlighting continues just after the match.  The syntax group
  1010.    that is expected to be present just after the match must be specified.
  1011.    This can be used when the previous method doesn't work well.  It's much
  1012.    slower, because more text needs to be parsed.
  1013. Both types of sync patterns can be used at the same time.
  1014.  
  1015. Besides the sync patterns, other matches and regions can be specified, to
  1016. avoid finding unwanted matches.
  1017.  
  1018. [The reason that the sync patterns are given separately, is that mostly the
  1019. search for the sync point can be much simpler than figuring out the
  1020. highlighting.  The reduced number of patterns means it will go (much)
  1021. faster.]
  1022.  
  1023.     :syntax sync match {group-name} grouphere {sync-group-name} ..
  1024.  
  1025.     Define a match that is used for syncing.  {sync-group-name} is the
  1026.     name of a syntax group that follows just after the match.  Parsing
  1027.     of the text for highlighting starts just after the match.  A region
  1028.     must exist for this sync-group-name.  The first one defined will be
  1029.     used.  "NONE" can be used for when there is no syntax group after the
  1030.     match.
  1031.  
  1032.     :syntax sync match {group-name} groupthere {sync-group-name} ..
  1033.  
  1034.     Like "grouphere", but {sync-group-name} is the name of a syntax
  1035.     group that is to be used at the start of the line where searching
  1036.     for the sync point started.  The text between the match and the
  1037.     start of the sync pattern searching is assumed not to change the
  1038.     syntax highlighting.  For example, in C you could search backwards for
  1039.     "/*" and "*/".  If "/*" is found first, you know that you are inside a
  1040.     comment, so the "groupthere" is "cComment".  If "*/" is found first,
  1041.     you know that you are not in a comment, so the "groupthere" is "NONE".
  1042.     (in practice it's a bit more complicated, because the "*/" and "*/"
  1043.     could appear inside a string.  That's left as an exercise to the
  1044.     reader...).
  1045.  
  1046.     :syntax sync match ..
  1047.     :syntax sync region ..
  1048.  
  1049.     Without a "groupthere" argument.  Define a region or match that is
  1050.     skipped while searching for a sync point.
  1051.  
  1052.     :syntax sync linecont {pattern}
  1053.  
  1054.     When {pattern} matches in a line, it is considered to continue in
  1055.     the next line.  This means that the search for a sync point will
  1056.     consider the lines to be concatenated.
  1057.  
  1058. If the "maxlines={N}" argument is given too, the number of lines that are
  1059. searched for a match is restricted to N.  This is useful if you have very
  1060. few things to sync on and a slow machine.  Example:
  1061. >  :syntax sync maxlines=100
  1062.  
  1063. You can clear all sync settings with:
  1064. >  :syntax sync clear
  1065.  
  1066. You can clear specific sync patterns with:
  1067. >  :syntax sync clear {group-name} ..
  1068.  
  1069. ==============================================================================
  1070. 8. Listing syntax items                    *:syntax* *:sy* *:syn*
  1071.  
  1072. This commands lists all the syntax items:
  1073.  
  1074.     :syntax [list]
  1075.  
  1076. To show the syntax items for one syntax group:
  1077.  
  1078.     :syntax list {group-name}
  1079.  
  1080. See above for other arguments for the ":syntax" command.
  1081.  
  1082. Note that the ":syntax" command can be abbreviated to ":sy", although ":syn"
  1083. is mostly used, because it looks better.
  1084.  
  1085. ==============================================================================
  1086. 9. Highlight command                    *:highlight*
  1087.  
  1088. There are two types of highlight groups:
  1089. - The ones used for specific languages.  For these the name starts with the
  1090.   name of the language.  Many of these don't have any attributes, but are
  1091.   linked to a group of the second type.
  1092. - The ones used for all languages.  These are also used for the 'highlight'
  1093.   option.
  1094.  
  1095. :highlight        List all the current highlight groups that have
  1096.             attributes set.
  1097.  
  1098. :highlight {group-name}
  1099.             List one highlight group.
  1100.  
  1101. :highlight clear {group-name}
  1102. :highlight {group-name} NONE
  1103.             Disable the highlighting for one highlight group.
  1104.  
  1105. :highlight {group-name} {key}={arg} ..
  1106.             Add a highlight group, or change the highlighting for
  1107.             an existing group.  See below for the arguments
  1108.             |highlight-args|.
  1109.  
  1110. Normally a highlight group is added once, in the *.vim file.  This sets
  1111. the default values for the highlighting.  After that, you can use additional
  1112. highlight commands to change the arguments that you want to set to
  1113. non-default values.  The value "NONE" can be used to switch the value off or
  1114. go back to the default value.
  1115.  
  1116. Example.  The syntax.vim file contains this line:
  1117. >  hi Comment    term=bold ctermfg=Cyan guifg=#80a0ff
  1118.  
  1119. You can change this by giving another ":highlight: command:
  1120. >  hi Comment    gui=bold
  1121.  
  1122. Note that all settings that are not included remain the same, only the
  1123. specified field is used, and settings are merged with previous ones.  So, the
  1124. result is like this single command has been used:
  1125. >  hi Comment    term=bold ctermfg=Cyan guifg=#80a0ff gui=bold
  1126.  
  1127.                         *highlight-args*
  1128. There are three types of terminals for highlighting:
  1129. term    a normal terminal (vt100, xterm)
  1130. cterm    a color terminal (MS-DOS console, color-xterm, these have the "Co"
  1131.     termcap entry)
  1132. gui    the GUI
  1133.  
  1134. For each type the highlighting can be given.  This makes it possible to use
  1135. the same syntax file on all terminals, and use the optimal highlighting.
  1136.  
  1137. 1. highlight arguments for normal terminals
  1138.  
  1139. term={attr-list}                *attr-list* *highlight-term*
  1140.     attr-list is a comma separated list (without spaces) of the
  1141.     following items (in any order):
  1142.         bold
  1143.         underline
  1144.         reverse
  1145.         inverse        same as reverse
  1146.         italic
  1147.         standout
  1148.         NONE        no attributes used (used to reset it)
  1149.  
  1150.     Note that "bold" can be used here and by using a bold font.  They
  1151.     have the same effect.
  1152.  
  1153. start={term-list}                *highlight-start*
  1154. stop={term-list}                *term-list* *highlight-stop*
  1155.     These lists of terminal codes can be used to get
  1156.     non-standard attributes on a terminal.
  1157.  
  1158.     The escape sequence specified with the "start" argument
  1159.     is written before the characters in the highlighted
  1160.     area.  It can be anything that you want to send to the
  1161.     terminal to highlight this area.  The escape sequence
  1162.     specified with the "stop" argument is written after the
  1163.     highlighted area.  This should undo the "start" argument.
  1164.     Otherwise the screen will look messed up.
  1165.  
  1166.     The {term-list} can have two forms:
  1167.  
  1168.     1. A string with escape sequences.
  1169.        This is any string of characters, except that it can't start with
  1170.        "t_" and blanks are not allowed.  The <> notation is recognized
  1171.        here, so you can use things like "<Esc>" and "<Space>".  Example:
  1172.         start=<Esc>[27h;<Esc>[<Space>r;
  1173.  
  1174.     2. A list of terminal codes.
  1175.        Each terminal code has the form "t_xx", where "xx" is the name of
  1176.        the termcap entry.  The codes have to be separated with commas.
  1177.        White space is not allowed.  Example:
  1178.         start=t_C1,t_BL
  1179.        The terminal codes must exist for this to work.
  1180.  
  1181.  
  1182. 2. highlight arguments for color terminals
  1183.  
  1184. cterm={attr-list}                    *highlight-cterm*
  1185.     See above for the description of {attr-list} |attr-list|.
  1186.     The "cterm" argument is likely to be different from "term", when
  1187.     colors are used.  For example, in a normal terminal comments could
  1188.     be underlined, in a color terminal they can be made Blue.
  1189.     Note: Many terminals (e.g., DOS console) can't mix these attributes
  1190.     with coloring.  Use only one of "cterm=" OR "ctermfg=" OR "ctermbg=".
  1191.  
  1192. ctermfg={color-nr}                    *highlight-ctermfg*
  1193. ctermbg={color-nr}                    *highlight-ctermbg*
  1194.     The {color-nr} argument is a color number.  Its range is zero to
  1195.     (not including) the number given by the termcap entry "Co".
  1196.     The actual color with this number depends on the type of terminal
  1197.     and its settings.  Sometimes the color also depends on the settings of
  1198.     "cterm".  For example, on some systems "cterm=bold ctermfg=3" gives
  1199.     another color, on others you just get color 3.
  1200.  
  1201.     For an xterm this depends on your resources, and is a bit
  1202.     unpredictable.  See your xterm documentation for the defaults.  The
  1203.     colors for a color-xterm can be changed from the .Xdefaults file.
  1204.     Unfortunately this means that it's not possible to get the same colors
  1205.     for each user.  See |xterm-color| for info about color xterms.
  1206.  
  1207.     The MSDOS standard colors are fixed (in a console window), so these
  1208.     have been used for the names.  But the meaning of color names in X11
  1209.     are fixed, so these color settings have been used, to make the
  1210.     highlighting settings portable (complicated, isn't it?).  The
  1211.     following names are recognized, with the color number used:
  1212.  
  1213.         NR-16   NR-8    COLOR NAME ~
  1214.                             *cterm-colors*
  1215.         0        0        Black
  1216.         1        4        DarkBlue
  1217.         2       2        DarkGreen
  1218.         3       6        DarkCyan
  1219.         4       1        DarkRed
  1220.         5       5        DarkMagenta
  1221.         6       3        Brown
  1222.         7       7        LightGray, LightGrey, Gray, Grey
  1223.         8        0*        DarkGray, DarkGrey
  1224.         9        4*        Blue, LightBlue
  1225.         10        2*        Green, LightGreen
  1226.         11        6*        Cyan, LightCyan
  1227.         12        1*        Red, LightRed
  1228.         13        5*        Magenta, LightMagenta
  1229.         14        3*        Yellow
  1230.         15        7*        White
  1231.  
  1232.     The number under "NR-16" is used for 16-color terminals ('t_Co'
  1233.     greater than or equal to 16).  The number under "NR-8" is used for
  1234.     8-color terminals ('t_Co' less than 16).  The '*' indicates that the
  1235.     bold attribute is set for ctermfg.  In many 8-color terminals (e.g.,
  1236.     "linux"), this causes the bright colors to appear.  This doesn't work
  1237.     for background colors!  Without the '*' the bold attribute is removed.
  1238.     If you want to set the bold attribute in a different way, put a
  1239.     "cterm=" argument AFTER the "ctermfg=" or "ctermbg=" argument.  Or use
  1240.     a number instead of a color name.
  1241.  
  1242.     The case of the color names is ignored.
  1243.  
  1244.     Note that for some color terminals these names may result in the wrong
  1245.     colors!
  1246.  
  1247.     When setting the "ctermfg" or "ctermbg" colors for the Normal group,
  1248.     these will become the colors used for the non-highlighted text.
  1249.     When setting the "ctermbg" color for the Normal group, the
  1250.     'background' option will be adjusted automatically.  This causes the
  1251.     highlight groups that depend on 'background' to change!  This means
  1252.     you should set the colors for Normal first, before setting other
  1253.     colors.
  1254.  
  1255.     When you have set "ctermfg" or "ctermbg" for the Normal group, Vim
  1256.     needs to reset the color when exiting.  This is done with the "op"
  1257.     termcap entry |t_op|.  If this doesn't work correctly, try setting the
  1258.     't_op' option in your .vimrc.
  1259.  
  1260.  
  1261. 3. highlight arguments for the GUI
  1262.  
  1263. gui={attr-list}                        *highlight-gui*
  1264.     These give the attributes to use in the GUI mode.
  1265.     See |attr-list| for a description.
  1266.     Note that "bold" can be used here and by using a bold font.  They
  1267.     have the same effect.
  1268.  
  1269. font={font-name}                    *highlight-font*
  1270.     font-name is the name of a font, as it is used on the system Vim
  1271.     runs on.  For X11 this is a complicated name, for example:
  1272. >  font=-misc-fixed-bold-r-normal--14-130-75-75-c-70-iso8859-1
  1273.  
  1274.     The font-name "NONE" can be used to revert to the default font.
  1275.     When setting the font for the "Normal" group, this becomes the default
  1276.     font (until the 'guifont' option is changed; the last one set is
  1277.     used).  All fonts used should be of the same character size as the
  1278.     default font!  Otherwise redrawing problems will occur.
  1279.  
  1280. guifg={color-name}                    *highlight-guifg*
  1281. guibg={color-name}                    *highlight-guibg*
  1282.     These give the foreground (guifg) and background (guibg) color to
  1283.     use in the GUI.  There are a few special names:
  1284.         NONE        no color (transparant)
  1285.         bg        use normal background color
  1286.         background    use normal background color
  1287.         fg        use normal foreground color
  1288.         foreground    use normal foreground color
  1289.     To use a color name with an embedded space or other special character,
  1290.     put it in single quotes.  The single quote cannot be used then.
  1291.     Example:
  1292. >        :hi comment guifg='salmon pink'
  1293.  
  1294.                             *gui-colors*
  1295.     Suggested color names (these are available on most systems):
  1296.         Red        LightRed    DarkRed
  1297.         Green    LightGreen    DarkGreen    SeaGreen
  1298.         Blue    LightBlue    DarkBlue    SlateBlue
  1299.         Cyan    LightCyan    DarkCyan
  1300.         Magenta    LightMagenta    DarkMagenta
  1301.         Yellow    LightYellow    Brown
  1302.         Gray    LightGray    DarkGray
  1303.         Black    White
  1304.         Orange    Purple        Violet
  1305.  
  1306.     In the Win32 GUI version, additional system colors are available.  See
  1307.     |win32-colors|.
  1308.  
  1309.     You can also specify a color by its Red, Green and Blue values.
  1310.     The format is "#rrggbb", where
  1311.         "rr"    is the Red value
  1312.         "bb"    is the Blue value
  1313.         "gg"    is the Green value
  1314.     All values are hexadecimal, range from "00" to "ff".  Examples:
  1315. >  :highlight Comment guifg=#11f0c3 guibg=#ff00ff
  1316.  
  1317.                     *highlight-groups* *highlight-default*
  1318. These are the default highlighting groups.  These groups are used by the
  1319. 'highlight' option default.  Note that the highlighting depends on the value
  1320. of 'background'.
  1321.                             *hl-Cursor*
  1322. Cursor        the character under the cursor
  1323.                             *hl-Directory*
  1324. Directory    directory names (and other special names in listings)
  1325.                             *hl-ErrorMsg*
  1326. ErrorMsg    error messages
  1327.                             *hl-IncSearch*
  1328. IncSearch       'incsearch' highlighting
  1329.                             *hl-ModeMsg*
  1330. ModeMsg        'showmode' message (e.g., "-- INSERT --")
  1331.                             *hl-MoreMsg*
  1332. MoreMsg        |more-prompt|
  1333.                             *hl-NonText*
  1334. NonText        '~' and '@' at the end of the window and characters from
  1335.         'showbreak'
  1336.                             *hl-Question*
  1337. Question    |hit-return| prompt and yes/no questions
  1338.                             *hl-SpecialKey*
  1339. SpecialKey    Meta and special keys listed with ":map"
  1340.                             *hl-StatusLine*
  1341. StatusLine    status line of current window
  1342.                             *hl-StatusLineNC*
  1343. StatusLineNC    status lines of not-current windows
  1344.                             *hl-Title*
  1345. Title        titles for output from ":set all", ":autocmd" etc.
  1346.                             *hl-Visual*
  1347. Visual        Visual mode selection
  1348.                             *hl-WarningMsg*
  1349. WarningMsg    warning messages
  1350.                             *hl-LineNr*
  1351. LineNr        line number for ":number" and ":#" commands
  1352.                             *hl-Normal*
  1353. Normal        normal text
  1354.                             *hl-Search*
  1355. Search        last search pattern highlighting (see 'hlsearch')
  1356.  
  1357.  
  1358. For the GUI you can use these groups to set the colors for the menu and
  1359. scrollbars.  They don't have defaults.  This doesn't work for the Win32 GUI.
  1360.     Menu                            *hl-Menu*
  1361.     Scrollbar                            *hl-Scrollbar*
  1362.  
  1363. ==============================================================================
  1364. 10. Linking groups                    *:highlight-link*
  1365.  
  1366. When you want to use the same highlighting for several syntax groups, you
  1367. can do this more easily by linking the groups into one common highlight
  1368. group, and give the color attributes only for that group.
  1369.  
  1370.     :highlight[!] link {from-group} {to-group}
  1371.  
  1372. Notes:
  1373. - If the {from-group} and/or {to-group} doesn't exist, it is created.  You
  1374.   don't get an error message for a non-existing group.
  1375. - If the {to-group} is "NONE", the link is removed from the {from-group}.
  1376. - As soon as you use a ":highlight" command for a linked group, the link is
  1377.   removed.
  1378. - If there are already highlight settings for the {from-group}, the link is
  1379.   not made, unless the '!' is given.  For a ":highlight link" command in a
  1380.   sourced file, you don't get an error message.  This can be used to skip
  1381.   links for groups that already have settings.
  1382.  
  1383. ==============================================================================
  1384. 11. Cleaning up                        *:syn-clear*
  1385.  
  1386. If you want to clear the syntax stuff for the current buffer, you can use this
  1387. command:
  1388. >  :syntax clear
  1389.  
  1390. This command should be used when you want to switch off syntax highlighting,
  1391. or when you want to switch to using another syntax.  It's a good idea to
  1392. include this command at the beginning of a syntax file.
  1393.  
  1394. If you want to disable syntax highlighting for all buffers, you need to remove
  1395. the autocommands that load the syntax files:
  1396. >  :syntax off
  1397.  
  1398. What this command actually does, is executing the command
  1399. >  source $VIM/syntax/nosyntax.vim
  1400. See the "nosyntax.vim" file for details.  Note that for this to work $VIM must
  1401. be valid.  See |$VIM|.
  1402.  
  1403. To clean up specific syntax groups for the current buffer:
  1404. >  :syntax clear {group-name} ..
  1405. This removes all patterns and keywords for {group-name}.
  1406.  
  1407. ==============================================================================
  1408. 12. Highlighting tags                    *tag-highlight*
  1409.  
  1410. If you want to highlight all the tags in your file, you can use the following
  1411. mappings.
  1412.  
  1413.     <F11>    -- Generate tags.vim file, and highlight tags.
  1414.     <F12>    -- Just highlight tags based on existing tags.vim file.
  1415.  
  1416. >  map <F11>  :sp tags<CR>:%s/^\([^    :]*:\)\=\([^    ]*\).*/syntax keyword Tag \2/<CR>:wq! tags.vim<CR>/^<CR><F12>
  1417. >  map <F12>  :so tags.vim<CR>
  1418.  
  1419. WARNING: The longer the tags file, the slower this will be, and the more
  1420. memory Vim will consume.
  1421.  
  1422. Only highlighting typedefs, unions and structs can be done too.  For this you
  1423. must use Exhuberant ctags (included with Vim).
  1424.  
  1425. Put these lines in your Makefile:
  1426.  
  1427. # Make a highlight file for types.  Requires Exhuberant ctags and awk
  1428. types: types.vim
  1429. types.vim: *.[ch]
  1430.     ctags -i=gstuS -o- *.[ch] |\
  1431.         awk 'BEGIN{printf("syntax keyword Type\t")}\
  1432.             {printf("%s ", $$1)}END{print ""}' > $@
  1433.  
  1434. And put these lines in your .vimrc:
  1435.  
  1436. >  " load the types.vim highlighting file, if it exists
  1437. >  autocmd BufRead,BufNewFile *.[ch] let fname = expand('<afile>:p:h') . '/types.vim'
  1438. >  autocmd BufRead,BufNewFile *.[ch] if file_readable(fname)
  1439. >  autocmd BufRead,BufNewFile *.[ch]   exe 'so ' . fname
  1440. >  autocmd BufRead,BufNewFile *.[ch] endif
  1441.  
  1442. ==============================================================================
  1443. 13. Color xterms                *xterm-color* *color-xterm*
  1444.  
  1445. Most color xterms have only eight colors.  They should work with these
  1446. lines in your .vimrc:
  1447. >  :if has("terminfo")
  1448. >  :  set t_Co=8
  1449. >  :  set t_Sf=<Esc>[3%p1%dm
  1450. >  :  set t_Sb=<Esc>[4%p1%dm
  1451. >  :else
  1452. >  :  set t_Co=8
  1453. >  :  set t_Sf=<Esc>[3%dm
  1454. >  :  set t_Sb=<Esc>[4%dm
  1455. >  :endif
  1456.     [<Esc> is a real escape, type CTRL-V <Esc>]
  1457.  
  1458. You might want to put these lines in an ":if" that checks the name of your
  1459. terminal, for example:
  1460. >  :if &term =~ "xterm"
  1461.    put above lines here
  1462. >  :endif
  1463.  
  1464. Note: Do these settings BEFORE doing ":syntax on".  Otherwise the colors may
  1465. be wrong.
  1466.  
  1467. To test your color setup, a file has been included in the Vim distribution.
  1468. To use it, execute these commands:
  1469. >  :e $VIM/syntax/colortest.vim
  1470. >  :so %
  1471.  
  1472. Some versions of xterm (and other terminals, like the linux console) can
  1473. output lighter foreground colors, even though the number of colors is defined
  1474. at 8.  Therefore Vim sets the "cterm=bold" attribute for light foreground
  1475. colors, when 't_Co' is 8.
  1476.  
  1477. To get 16 colors, get the newest xterm version (which should be included with
  1478. Xfree86 3.3).  You can also find the latest version at:
  1479.     http://www.clark.net/pub/dickey/xterm
  1480. You probably have to enable 16 colors when running configure:
  1481.     ./configure --disable-bold-color
  1482. If you only get 8 colors, check the xterm compilation settings.
  1483.  
  1484. This xterm should work with these lines in your .vimrc:
  1485. >  :if has("terminfo")
  1486. >  :  set t_Co=16
  1487. >  :  set t_AB=<Esc>[%?%p1%{8}%<%t%p1%{40}%+%e%p1%{92}%+%;%dm
  1488. >  :  set t_AF=<Esc>[%?%p1%{8}%<%t%p1%{30}%+%e%p1%{82}%+%;%dm
  1489. >  :else
  1490. >  :  set t_Co=16
  1491. >  :  set t_Sf=<Esc>[3%dm
  1492. >  :  set t_Sb=<Esc>[4%dm
  1493. >  :endif
  1494.     [<Esc> is a real escape, type CTRL-V <Esc>]
  1495.  
  1496. Without |+terminfo|, Vim will recognize these settings, and automatically
  1497. translate cterm colors of 8 and above to "<Esc>[9%dm" and "<Esc>[10%dm".
  1498.  
  1499. Or just set the TERM environment variable to "xterm-16color" and try if that
  1500. works.
  1501.  
  1502. You probably want to use these X resouces (put them in your ~/.Xdefaults file):
  1503.     XTerm*color0:            #000000
  1504.     XTerm*color1:            #c00000
  1505.     XTerm*color2:            #008000
  1506.     XTerm*color3:            #808000
  1507.     XTerm*color4:            #0000c0
  1508.     XTerm*color5:            #c000c0
  1509.     XTerm*color6:            #008080
  1510.     XTerm*color7:            #c0c0c0
  1511.     XTerm*color8:            #808080
  1512.     XTerm*color9:            #ff6060
  1513.     XTerm*color10:            #00ff00
  1514.     XTerm*color11:            #ffff00
  1515.     XTerm*color12:            #8080ff
  1516.     XTerm*color13:            #ff40ff
  1517.     XTerm*color14:            #00ffff
  1518.     XTerm*color15:            #ffffff
  1519.     Xterm*cursorColor:        Black
  1520.  
  1521. [Note: The cursorColor is required to work around a bug, which changes the
  1522. cursor color to the color of the last drawn text.  This has been fixed by a
  1523. newer version of xterm, but not everybody is it using yet.]
  1524.  
  1525. To get these right away, reload the .Xdefaults file to the X Option database
  1526. Manager (you only need to do this when you just changed the .Xdefaults file):
  1527. >  xrdb -merge ~/.Xdefaults
  1528.  
  1529.  vim:tw=78:ts=8:sw=4
  1530.